﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using LIM.controller;
using Telerik.WinControls.UI.Export;

namespace LIM.forms
{
    public partial class radForm_CRM_DanhSachLienHe : Telerik.WinControls.UI.RadForm
    {
        public radForm_CRM_DanhSachLienHe()
        {
            InitializeComponent();
        }
        DanhMucLienHeController controller = new DanhMucLienHeController();
        private void radForm_CRM_DanhSachLienHe_Load(object sender, EventArgs e)
        {
            radGridView2.DataSource = controller.Load();
        }

        private void radGridView2_CellDoubleClick(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            if (radGridView2.SelectedRows.Count > 0)
            {
                if (radGridView2.SelectedRows[0].Cells[0].Value != null)
                {
                    radForm_CRM_LienHe_ChiTiet frm = new radForm_CRM_LienHe_ChiTiet();
                    frm.RowIDLienHe = int.Parse(radGridView2.SelectedRows[0].Cells[0].Value.ToString());
                    frm.controller = controller;
                    frm.MdiParent = this.MdiParent;
                    frm.Text = radGridView2.SelectedRows[0].Cells[1].Value.ToString();
                    frm.Tag = frm.RowIDLienHe;
                    frm.Show();
                }
            }
        }

        private void radMenuItem1_Click(object sender, EventArgs e)
        {
            radForm_CRM_DanhSachLienHe_Load(sender, e);
        }

        private void radMenuItem_ExportExcel_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Excel file(*.xls)|*.xls|Excel file(*.xlsx)|*.xlsx";
            saveFileDialog.FilterIndex = 1;
            saveFileDialog.InitialDirectory = @"C:\";
            saveFileDialog.Title = "Export Excel File To";
            string strFileName="";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
                strFileName = saveFileDialog.FileName;
            if (strFileName != String.Empty)
            {
                ExportToExcelML exporter = new ExportToExcelML(this.radGridView2);
                exporter.HiddenColumnOption = Telerik.WinControls.UI.Export.HiddenOption.DoNotExport;
                exporter.ExportVisualSettings = true;
                exporter.SheetMaxRows = ExcelMaxRows._1048576;
                exporter.SheetName = "Sheet";
                exporter.SummariesExportOption = SummariesOption.DoNotExport;
                exporter.RunExport(strFileName);
            }


            
        }
    }
}
